package demo3;

public class Text02 {
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            while (true) {
                //获取线程对象
                Thread thread = Thread.currentThread();
                System.out.println(thread.getName() + " hello thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        //启动t1
//        t1.start();

        //指定线程名
        Thread t2 = new Thread(() -> {
            while (true) {
                //获取类名
                String cName = Text02.class.getName();
                //获取当前执行的方法名
                String mName = Thread.currentThread().getStackTrace()[1].getMethodName();
                //获取线程对象
                Thread thread = Thread.currentThread();
                //获取线程名
                String tName = thread.getName();

//                System.out.println(thread.getName() + " 我是一个有名字的线程...");
                System.out.println("当前类：" + cName + ", 当前方法：" + mName + ", 当前线程：" + tName);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        }, "我是一个线程");
        //启动t2
        t2.start();
    }
}
